#include <vector>
using std::vector;

class Solution {
public:
    bool canEatAll(vector<int>& piles, int h, int k) {
        int time = 0;
        for (int i = 0; i < piles.size(); i++) {
            time += (piles[i] - 1) / k + 1;
        }
        return time <= h;
    }

    int minEatingSpeed(vector<int>& piles, int h) {
        int left = 1;
        int right = pow(10, 9);
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (!canEatAll(piles, h, mid)) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left;
    }
};